# Maintainer: Tao zuhong <taozuhong@hotmail.com>

_realname=libcloudproviders
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.6
pkgrel=1
url="https://gitlab.gnome.org/World/libcloudproviders"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
pkgdesc="libcloudproviders is a DBus API that allows cloud storage sync clients to expose their services. (mingw-w64)"
license=('spdx:LGPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("https://download.gnome.org/sources/libcloudproviders/${pkgver%.*}/libcloudproviders-${pkgver}.tar.xz")
noextract=("libcloudproviders-${pkgver}.tar.xz")
sha256sums=('3b75110b3a4fdef4c5c5a440e48701fe054d2ae061d156c89136bb5ba05e74b7')

prepare() {
  tar -xf "libcloudproviders-${pkgver}.tar.xz" || true
  cd "${srcdir}/libcloudproviders-${pkgver}"
}

build() {
  msg "Build static version"
  mkdir "${srcdir}"/build-${MSYSTEM}-static && cd "${srcdir}"/build-${MSYSTEM}-static

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("--buildtype=release")
  else
    extra_config+=("--buildtype=debug")
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --default-library=static \
    "../libcloudproviders-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile

  msg "Build shared version"
  mkdir "${srcdir}"/build-${MSYSTEM}-shared && cd "${srcdir}"/build-${MSYSTEM}-shared

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    -Ddefault_library=shared \
    "../libcloudproviders-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}-static"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

  cd "${srcdir}/build-${MSYSTEM}-shared"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

  install -Dm644 "${srcdir}/libcloudproviders-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
